Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle multiple function calls in openai #346

Closed

Conversation

jeevan057
Copy link

openai can give multiple tool calls
ex : "message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_cuC7cq3IoIqCN2IvwfGuNl8J",
"type": "function",
"function": {
"name": "add_numbers",
"arguments": "{"a": 1, "b": 2}"
}
},
{
"id": "call_SfbHakQINYSeK9a7VzQq50OW",
"type": "function",
"function": {
"name": "add_numbers",
"arguments": "{"a": 3, "b": 4}"
}
}
],
"refusal": null
},

The current implementation assumes only single function call. In this case we get function name as add_numbersadd_numbers (here we have function name twice ). This would fail when the openai is giving multiple tool calls.

The fix I used is create a list of function names and call them.

…nly one function call at a time. Fixed this to handle multiple function calls.
@jeevan057 jeevan057 changed the title handle multiple function calls handle multiple function calls in openai Aug 7, 2024
@aconchillo
Copy link
Contributor

This is awesome. Thank you! @chadbailey59 what do you think?

@cartesis07
Copy link

Great thanks!

@szeka94
Copy link

szeka94 commented Sep 7, 2024

any concerns merging this? I'm running into the same error.

Copy link
Contributor

@kwindla kwindla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Just needs one tiny fix.

tool_id_list.append(tool_call_id)
for function_name,arguments,tool_id in zip(functions_list,arguments_list,tool_id_list):
if self.has_function(function_name):
await self._handle_function_call(context, tool_call_id, function_name, arguments)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument here should be tool_id not tool_call_id.

@kwindla
Copy link
Contributor

kwindla commented Sep 30, 2024

Oof. Enough stuff has changed out from under this PR that there needs to be some more code in the context aggregator to make this work, now.

I'll figure this out tonight and post another PR.

Thank you for doing the work, here ... we'll get this into the next Pipecat release!

@kwindla
Copy link
Contributor

kwindla commented Sep 30, 2024

Merged as this PR: #522

@kwindla kwindla closed this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants